/**
 * 事件详情数据过滤
 *
 * @author 阳坤（1194636148@qq.com）
 * @date   时间：2022/12/12
 */

import { getDict } from '@/core/dictionaries'
import { get } from '@/utils'

export const filterEventDetail = (data, eventType) => {
  console.log('eventType', eventType)
  if (eventType === 'JGB1') return getHightjtgz(data) // 高速交通管制
  else if (eventType === 'TBB1') return getHightEltq(data) // 高速恶劣天气
  else if (eventType === 'JEB1') return getHightSgyh(data) // 高速施工养护
  else if (eventType === 'TDB2') return getHightZaw(data) // 高速障碍物
  else if (eventType === 'TDB1') return getHightDll(data) // 高速大流量
  // 得到高速事故详情
  else return getHighAccident(data)
}

/**
 * 得到高速事故详情
 *
 */
const getHighAccident = data => {
  const happenTime = { title: '发生时间：' }
  const eventSourceName = { title: '事件来源：' }
  const location = { title: '所在位置：' }
  const describe = { title: '方 向：' }
  const trafficInfluence = { title: '道路影响：' }
  const orgName = { title: '管辖单位：' }
  const eventDesc = { title: '事件描述：' }
  if (data.happenTime) happenTime.value = data.happenTime
  if (data.eventSourceName) eventSourceName.value = data.eventSourceName
  location.value = getLocation([data.startStake, data.endStake])
  if (data.describe) describe.value = data.describe
  if (data.trafficInfluence) trafficInfluence.value = data.trafficInfluence
  if (data.orgName) orgName.value = data.orgName
  if (data.eventDesc) eventDesc.value = data.eventDesc
  return [happenTime, eventSourceName, location, describe, trafficInfluence, orgName, eventDesc]
}

/**
 * @desc 检索交通管制字段
 * **/
function getHightjtgz(data) {
  return [
    { title: '发生时间：', value: get(data, 'eventTsClose.createtime') },
    { title: '事件来源：', value: get(data, 'eventSourceName') },
    { title: '所在位置：', value: get(data, '') },
    { title: '方 向： ', value: get(data, 'describe') },
    { title: '道路影响：', value: get(data, 'trafficInfluence') },
    { title: '管辖单位：', value: get(data, 'eventTsClose.unitname') },
    { title: '事件描述：', value: get(data, 'eventTsClose.accidentdesc') }
  ]
}

/**
 * 检索恶劣天气字段
 *
 * **/
function getHightEltq(data) {
  const roadNum = get(data, 'eventBadWeather.roadNum', '')
  const startPos = get(data, 'eventBadWeather.startPos', '')
  // const endPos = get(data, 'eventBadWeather.endPos', '')
  return [
    { title: '发生时间：', value: get(data, 'eventBadWeather.createTime') },
    { title: '事件来源：', value: get(data, 'eventSourceName') },
    { title: '所在位置：', value: `${roadNum} ${startPos}` },
    { title: '方 向： ', value: get(data, 'describe') },
    { title: '道路影响：', value: get(data, 'trafficInfluence') },
    { title: '管辖单位：', value: get(data, 'eventBadWeather.eventVO.unitname') },
    { title: '事件描述：', value: get(data, 'eventBadWeather.eventVO.accidentdesc') }
  ]
}

/**
 * 检索施工养护字段
 *
 * **/
function getHightSgyh(data) {
  const roadNum = get(data, 'eventSg.event.roadid', '')
  const startK = get(data, 'eventSg.event.strposition', '')
  const startM = get(data, 'eventSg.event.strmileage', '')
  const endK = get(data, 'eventSg.event.endposition', '')
  const endM = get(data, 'eventSg.event.endmileage', '')
  return [
    { title: '发生时间：', value: get(data, 'eventSg.starttime') },
    { title: '事件来源：', value: get(data, 'eventSourceName') },
    { title: '所在位置：', value: `${roadNum} K${startK}+${startM}-${endK}+${endM}` },
    { title: '方 向： ', value: get(data, 'eventSg.event.roaddirectio') },
    { title: '道路影响：', value: get(data, 'trafficInfluence') },
    { title: '管辖单位：', value: get(data, 'eventSg.event.unitname') },
    { title: '事件描述：', value: get(data, 'eventSg.event.accidentdesc') }
  ]
}

/**
 * 检索高速障碍物字段
 *
 * **/
function getHightZaw(data) {
  return [
    { title: '发生时间：', value: get(data, 'eventZaw.eventTime') },
    { title: '事件来源：', value: get(data, 'eventSourceName') },
    { title: '所在位置：', value: get(data, 'eventAddress') },
    { title: '方 向： ', value: get(data, 'eventZaw.direction') },
    { title: '道路影响：', value: get(data, 'trafficInfluence') },
    { title: '管辖单位：', value: get(data, 'eventZaw.unitShortName') },
    { title: '事件描述：', value: get(data, 'eventZaw.eventDesc') }
  ]
}

/**
 * 检索高速大流量字段
 *
 * **/
function getHightDll(data) {
  const roadNum = get(data, 'eventFlow.eventFlowBean.fvcRoadId', '')
  const startK = get(data, 'eventFlow.eventFlowBean.fstrPosition', '')
  const startM = get(data, 'eventFlow.eventFlowBean.fstrMileage', '')
  const endK = get(data, 'eventFlow.eventFlowBean.fendPosition', '')
  const endM = get(data, 'eventFlow.eventFlowBean.fendMileage', '')
  return [
    { title: '发生时间：', value: get(data, 'eventFlow.eventFlowBean.fcreateTime') },
    { title: '事件来源：', value: get(data, 'eventSourceName') },
    { title: '所在位置：', value: `${roadNum} K${startK}+${startM}-${endK}+${endM}` },
    { title: '方 向： ', value: get(data, 'eventFlow.eventFlowBean.fvcRoadDirectIo') },
    { title: '道路影响：', value: get(data, 'trafficInfluence') },
    { title: '管辖单位：', value: get(data, 'eventFlow.eventFlowBean.funitName') },
    { title: '事件描述：', value: get(data, 'eventFlow.eventFlowBean.faccidentDesc') }
  ]
}

/**
 * 得到桩号
 * data.length
 *
 */
const getLocation = data => {
  if (data.length == 2) {
    const startStake = data[0] ? data[0] : ''
    const endStake = data[1] ? data[1] : ''
    return `${startStake}${endStake}`
  } else if (data.length == 4) {
    const startStakeK = data[0] ? 'K' + data[0] : ''
    const startStakeM = data[1] ? '+' + data[1] : ''
    const endStakeK = data[2] ? '-K' + data[2] : ''
    const endStakeM = data[3] ? '+' + data[3] : ''
    return `${startStakeK}${startStakeM}${endStakeK}${endStakeM}`
  }
}
